package cn.edu.gzgs.controller;


import cn.edu.gzgs.dto.AuditRecordDTO;
import cn.edu.gzgs.result.Result;
import cn.edu.gzgs.service.AuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Tag(name = "审核工作量申报管理接口", description = "审核工作量申报和佐证材料") // 类级标签
@RestController
@RequestMapping("/api/audit")
@Slf4j
public class AuditManageController {

    @Autowired
    private AuditService auditService;

    /**
     * 审核工作量申报
     * @param auditRecordDTO
     * @return Result
     */
    @PutMapping("/auditing")
    @Operation(summary = "审核工作量申报")
    public Result audit(@RequestBody AuditRecordDTO auditRecordDTO) {
        log.info("审核内容：{}", auditRecordDTO);
        auditService.audit(auditRecordDTO);
        return Result.success();
    }

    /**
     * 驳回审核
     * @param id
     * @return Result
     */
    @PutMapping("/dismiss/{id}")
    @Operation(summary = "驳回审核")
    @Parameter(name = "id", description = "审核内容ID", required = true)
    public Result dismiss(@PathVariable Long id) {
        log.info("驳回审核内容：{}", id);
        auditService.dismissAudit(id);
        return Result.success();
    }

    /**
     * 下载佐证材料文件
     * @param materialId 佐证材料ID
     * @return 文件下载URL
     */
    @Operation(summary = "下载佐证材料文件")
    @PostMapping("/download/{materialId}")
    @Parameter(name = "materialId", description = "佐证材料ID", required = true)
    public Result<String> downloadFile(@PathVariable Long materialId) throws Exception {
        log.info("下载佐证材料文件，材料ID：{}", materialId);
        String downloadUrl = auditService.downloadSupportingMaterial(materialId);
        return Result.success(downloadUrl);
    }
}
